package top.chatgqt.SmartChargeStation.demo.netty.handlers;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import top.chatgqt.SmartChargeStation.demo.protobuf.UserProtobuf;

@Slf4j
public class ImoocClientProtobufHandler extends SimpleChannelInboundHandler<UserProtobuf.User> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, UserProtobuf.User msg) throws Exception {

    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        UserProtobuf.User user = UserProtobuf.User.newBuilder().setName("This is name").build();

        for (int i = 0; i < 100; i++) {
            log.info("发送{}次", i + 1);
            ctx.writeAndFlush(user);
        }


        super.channelActive(ctx);
    }
}
